package com.stars.empoly.adapter

import android.content.Context
import android.graphics.Color
import android.graphics.Typeface
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.LinearLayout
import android.widget.TextView
import com.hwangjr.rxbus.RxBus
import com.qmuiteam.qmui.kotlin.onClick
import com.qmuiteam.qmui.widget.QMUIRadiusImageView
import com.stars.empoly.R
import com.stars.empoly.config.ConfigRx
import com.stars.empoly.inte.ChoiceData
import com.stars.empoly.model.ShopLabel
import com.stars.empoly.model.bean.CateTypeBean
import java.util.*

/**
 *
 *on 2021/1/6
 */
class PointsTabsAdapter(var context: Context): BaseAdapter() {

    private var updata: ArrayList<CateTypeBean>?= null
    var choseData:ChoiceData?=null

    fun getData(): ArrayList<CateTypeBean> {
        return updata!!
    }

    fun setDeviceList(list: ArrayList<CateTypeBean>,choseData: ChoiceData) {
        this.choseData=choseData
        if (list != null) {
            updata = list.clone() as ArrayList<CateTypeBean>
            notifyDataSetChanged()
        }
    }

    fun clearDeviceList() {
        if (updata != null) {
            updata!!.clear()
        }
        notifyDataSetChanged()
    }


    override fun getCount(): Int {

        return if (updata == null) 0 else updata!!.size

    }

    override fun getItem(p0: Int): CateTypeBean {

        return updata!![p0]
    }

    override fun getItemId(p0: Int): Long {
        return 0
    }

    override fun getView(position: Int, view: View?, parent: ViewGroup?): View {

        var layout=view
        if (layout == null) {
            layout = LayoutInflater.from(context).inflate(
                R.layout.item_tabs_img,
                    parent, false)
            layout!!.tag = HotViewHolder(layout)
        }
        val holder = layout.tag as HotViewHolder
        val dEntity: CateTypeBean = updata!![position]

        holder.tv.text=dEntity.name

        if(dEntity.chose){
            holder.tv.setTextColor(Color.parseColor("#59C2A3"))
            holder.tv.typeface = Typeface.defaultFromStyle(Typeface.BOLD)

            holder.lin.visibility=View.VISIBLE

        }else{
            holder.tv.setTextColor(Color.parseColor("#999999"))
            holder.tv.typeface = Typeface.defaultFromStyle(Typeface.NORMAL)

            holder.lin.visibility=View.INVISIBLE
        }


        holder.ll.onClick {

            if(null!=choseData){
                choseData?.onRestuse(position.toString())
            }
//            RxBus.get().post(ConfigRx.CHOSE_POINT, position.toString())

        }


        return layout
    }


    class HotViewHolder(view: View) {

        var tv: TextView = view.findViewById(R.id.tv)
        var lin: View = view.findViewById(R.id.lin)

        var ll: LinearLayout = view.findViewById(R.id.ll)






    }

}
